
<template>
  <div class="NoCardhead bg-fff oh">
    <div v-wechat-title="$route.meta.title"></div>
    <ul class="pad-50" style="ma">
      <li style="margin-bottom: 20px;" @click="click('wk')">
        <img style="width: 100%;height: 100%;" src="../img/wukashoukuan@3x.png" alt />
      </li>
      <li @click="click('hkb')">
        <img style="width: 100%;height: 100%;" src="../img/shoukuanbao@3x.png" alt />
      </li>
    </ul>
    <van-cell @click="addCard()" style="background: rgba(243,244,248,1);" class="blue" title="我的信用卡" is-link />
  </div>
</template>
<script>
var $th = "";
import { Toast } from "vant";
export default {
  data() {
    return {
      host: "https://community.1818pay.cn/customer",
      // host:'http://192.168.1.187/customer',
      userid: "", //用户id,
      token: "",
      nameState: "" //实名状态
    };
  },
  async created() {
    $th = this;
    // try {
    //   if( $th.appEquipment.indexOf("Android") >-1){
    //      android.nativeMonitorButton("1","0");
    //   }else{
    //       window.webkit.messageHandlers.nativeMonitorButton.postMessage({
    //       back:"1",
    //       colse: "0"
    //     });
    //   }
      
    // } catch (error) {
    // }
    //获取id
    var id = this.getUrl("id");
    if (id) {
      localStorage.setItem("Userid", id); //用户id
    } else {
      id = localStorage.getItem("Userid");
    }
    $th.userid = id;
    //获取卡列表
    var tokenid = await this.$axios(
      this.host + "/getToken",
      {
        customerId: id
      },
      "post"
    );
    if (tokenid.code == "1000") {
      this.token = tokenid.data;
      console.log(this.token);
      // $th.creditCardList = reqXFindList.data;
    } else {
      $th.$toast(tokenid.message);
      return;
    }
  },

  methods: {
    addCard() {
       Toast.loading({
          message: '加载中...',
          forbidClick: true,
          duration:0
        });
      //添加储蓄卡
      axios
        .get(this.host + "/customer/feignCustomerInfo", {
          //是否实名
          params: {
            customerId: this.userid
          }
        })
        .then(res => {
          Toast.clear(); 
          if (res.data.code == "1000") {
             var ress = JSON.parse(res.data.data);
            if (ress.nameState == 1) {
              localStorage.setItem("token", $th.token);
              localStorage.setItem("customerId", $th.getUrl("id"));
              // $th.$router.push("/addCard");
              $th.$router.push("/cardList");
            } else {
              return $th.$toast("请先实名");
            }
          } else {
            return $th.$toast(res.data.message);
          }
        });
    },
    click(val) {
      //开启加载框
      Toast.loading({
          message: '加载中...',
          forbidClick: true,
          duration:0
        });
      axios
        .get(this.host + "/customer/feignCustomerInfo", {
          //是否实名
          params: {
            customerId: this.userid
          }
        })
        .then(res => {
          Toast.clear(); //关闭加载框 
          if (res.data.code == "1000") {
            var ress = JSON.parse(res.data.data);
            console.log(ress);
            $th.nameState = ress.nameState;
            if (ress.nameState == 1) {
              if (val == "wk") {
                window.location =
                  "https://community.1818pay.cn:1181/yj-jpos/index.html#/index2?id=" +
                  this.userid+'&'+Math.random();
              } else {
                window.location =
                  "https://community.1818pay.cn:1181/plan/index.html#/?token=" +
                  this.token+'&'+Math.random();
              }
            } else {
              return this.$toast("请先实名");
            }
          } else {
            return this.$toast(res.data.message);
          }
        });
    }
  }
};
</script>
<style >
.NoCardhead {
  padding-top: 0; 
  color: black;
}

.NoCardhead .ConHead {
  background-color: #fff;
  padding: 0.4rem 10px;
}

.NoCardhead .ConList {
  border-radius: 10px;
  /* margin: 20px 0; */
  padding-top: 20px;
}

.ConHead .ConHeadCon {
  /* width: 200px; */
}

.ConHead .ConHeadCon .img {
  float: left;
  margin-top: 3px;
  margin-right: 10px;
}
.pr {
  position: relative;
}
.pa {
  position: absolute;
}
.zhe {
  background: #5a5a5a;
  opacity: 0.9;
  color: white;
  padding: 5px 10px;
  font-size: 13px;
  border-radius: 5px;
  width: 85%;
  margin: 0 auto;
  line-height: 20px;
}
html,
body,
#app,
.NoCardhead {
  height: 100%;
}
.dl {
  display: inline-block;
}
.sanjiao {
  content: "";
  top: 2px;
  left: -38px;
  border-width: 0 7px 8px;
  border-style: solid;
  border-color: transparent transparent #696969;
  top: -7px;
  left: 5rem;
  z-index: 99;
}
</style>